<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/12
 * Time: 10:27
 * 获取一段时间内周一，周二，周三.......周天的天数
 */
$oa_oseid = $route->bodyParams['oa_oseid'];  //机构
$start_time = $route->bodyParams['start_time'];  //机构
$end_time = $route->bodyParams['end_time'];  //机构

//获取两个时间戳内相差几天
function count_days($a,$b){
    $a_dt=getdate($a);
    $b_dt=getdate($b);
    $a_new=mktime(12,0,0,$a_dt['mon'],$a_dt['mday'],$a_dt['year']);
    $b_new=mktime(12,0,0,$b_dt['mon'],$b_dt['mday'],$b_dt['year']);
    return round(abs($a_new-$b_new)/86400 + 1);
}

$countDate = count_days($start_time,$end_time);
//先获取开始时间是周几
$start_N = date('N',$start_time);
$end_N = date('N',$end_time);
//获取两个时间戳内有几周
$weekNum = floor($countDate/7);
$modNum = $countDate%7;
echo "这段时间有几天：".$countDate;
echo "这段时间有几周：".$weekNum;
echo "这段时间有余几天：".$modNum;
echo "开始时间是周几：".$start_N;
echo "结束时间是周几：".$end_N;
echo"<br/>";
$array = array(0,0,0,0,0,0,0);
if($weekNum >= 0){
    
    if($modNum>=0){
        if($start_N + $modNum > 7 ){
            echo "拐弯了";
            for($i = 0; $i<count($array); $i++ ){
                $array[$i] =  $array[$i] + $weekNum + 1;
            }
            for($start_N;$start_N>$end_N ;$start_N--){
                $array[$start_N-1] -= 1;
            }
        }else{
            echo "没拐弯";
            for($i = 0; $i<count($array); $i++ ){
                $array[$i] =  $array[$i] + $weekNum;
            }
            for($start_N;$start_N<=$modNum ;$start_N++){
                $array[$start_N-1] += 1;
            }
        }
        
    }
}
print_r($array);


//$sql = "SELECT SUM(oc_limit_number * (oc_weekday_frequency + oc_weekend_frequency)) AS limit_num FROM art_oa_classroom WHERE oc_oesid = ".$oa_oseid;
////$sql  = "SELECT oc_limit_number from art_oa_classroom WHERE oc_oesid = ".$oa_oseid;
//$re=$db->mysqlDB->query($sql);

//$response->responseData(true, $re);